<?php 
namespace App\Infra\User;

use App\Utils\ModelSDK\ModelOperator;
use App\Models\WeChatDoctorInfo;
use App\Models\WeChatDoctor;


class DoctorManage{

	use ModelOperator;

	public function getDoctorInfos($conditions){
		return $this->findModel(WeChatDoctorInfo::class,WeChatDoctorInfo::query(),$conditions,true)->get();
	}

	public function getDoctor($conditions){

		// dd(WeChatDoctorInfo::query()->with(['wechatDoctor'])->get()->toArray());

		return $this->findModel(WeChatDoctorInfo::class,WeChatDoctorInfo::query()->with(['wechatDoctor']),$conditions,$first = true);
	}

	public function getDoctorInfosByWith($conditions){
		return $this->findModel(WeChatDoctor::class,WeChatDoctor::query()->with(['wechatDoctorInfo']),$conditions);
	}

	public function getDoctorAndMessage($conditions){
		$query = WeChatDoctorInfo::query()->with(['messages' => function($query){
			$query->with(['replys' =>function($query){
				$query->orderBy('created_at','ASC');
			}])->with(['wechatUser'])->orderBy('created_at','DESC');
		}]);

		return $this->findModel(WeChatDoctorInfo::class,$query,$conditions);
	}
}